<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace app\cms\controller\admin;

class Nav extends \app\admin\common\AdminController
{
    protected $reserve_params = array('group');

    public function index($group = 'main')
    {
        $nav_list = model('cms/nav')->get_list_tree($group, 0);

        $this->assign('group', $group);
        $this->assign('nav_list', $nav_list);
        $this->display('admin/nav/nav_list');
    }

    public function create($group = 'main')
    {
        $nav_info = model('cms/nav')->initDefault();

        if (request()->isPost()) {
            $nav_info->acceptData($this->post_array());

            if ($nav_info->save() !== false) {
                $this->success('新增成功。', $this->url('index'));
            }
        }

        $this->assign('group', $group);
        $this->assign('nav_info', $nav_info);
        $this->display('admin/nav/nav_form');
    }

    public function modify($group = 'main', $id)
    {
        $nav_info = model('cms/nav')->findOrFail($id);

        if (request()->isPost()) {
            $nav_info->acceptData($this->post_array());

            if ($nav_info->save() !== false) {
                $this->success('修改成功。', $this->url('index'));
            }
        }

        $this->assign('group', $group);
        $this->assign('nav_info', $nav_info);
        $this->display('admin/nav/nav_form');
    }

    public function delete($id)
    {
        model('cms/nav')->delete_recursion($id);
        $this->success('删除成功。', $this->url('index'));
    }
}
